package com.fyzk.activity.chongzhi.epay;

import android.os.Handler;
import android.os.Message;

import org.json.JSONObject;

public class ResponseMessage {
    /**
     * "支付成功","支付失败"
     */
    public static final int[] errorCodes = {00000, 10001};
    /**
     * 支付成功
     */
    public static final int SUCCESS = 0;
    /**
     * 响应异常
     */
    public static final int RESPONSE = 1;
    /**
     * 请求异常
     */
    public static final int REQUEST = 2;
    /**
     * 未知异常
     */
    public static final int UNKNOWN = 3;
    /**
     * 取消支付
     */
    public static final int CANCEL = 4;

    public static void sendExceptionMessage(int code, Handler handler) {
        JSONObject responseData = new JSONObject();
        Message msg = Message.obtain();
        try {
            switch (code) {
                case SUCCESS:
                    responseData.put("status", "SUCCESS");
                    responseData.put("exceptionCode", "SUCCESS");
                    responseData.put("message", "支付成功");
                    msg.what = errorCodes[0];
                    break;
                case RESPONSE:
                    responseData.put("status", "EXCEPTION");
                    responseData.put("exceptionCode", "response.exception");
                    responseData.put("message", "响应异常");
                    msg.what = errorCodes[1];
                    break;
                case REQUEST:
                    responseData.put("status", "EXCEPTION");
                    responseData.put("exceptionCode", "request.exception");
                    responseData.put("message", "请求异常");
                    msg.what = errorCodes[1];
                    break;
                case UNKNOWN:
                    responseData.put("status", "EXCEPTION");
                    responseData.put("exceptionCode", "unknown.exception");
                    responseData.put("message", "未知异常");
                    msg.what = errorCodes[1];
                    break;
                case CANCEL:
                    responseData.put("status", "EXCEPTION");
                    responseData.put("exceptionCode", "cancel.exception");
                    responseData.put("message", "取消支付");
                    msg.what = errorCodes[1];
                    break;
                default:
                    break;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        msg.obj = responseData.toString();
        handler.sendMessage(msg);
    }
}
